package com.wangrui.sbnetty.controller;

import com.wangrui.sbnetty.server.WebSocketServer;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.nio.charset.StandardCharsets;

@RestController
@RequestMapping("/websocket")
public class WebsocketController {

    @GetMapping("/sendAll")
    public String sendAll(String message) {
        for (Channel channel : WebSocketServer.channels) {
            channel.writeAndFlush(new TextWebSocketFrame(message));
        }
        return "success";
    }
}
